package cc.ipost.ipost;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;

import com.umeng.analytics.MobclickAgent;

@SuppressLint("HandlerLeak")
public class LoadingActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MobclickAgent.onError(this);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.loading);
		route();
//			Intent i = new Intent(LoadingActivity.this,AddressActivity.class);
//			this.startActivity(i);
		

	}

	/**
	 * if user information found, go to MainActivity directly;
	 * else wait 2 seconds for logo stuff and then jump to AccountActivity
	 */
	public void route() {
		MyApplication ma = (MyApplication) getApplication();
		boolean isUser = ma.checkUser();
		if (isUser) {
			Intent i = new Intent(LoadingActivity.this, MainActivity.class);
			this.startActivity(i);
		} else {
			new Handler().postDelayed(new Runnable() {
				public void run() {
					Intent i = new Intent(LoadingActivity.this,
							AccountActivity.class);
					LoadingActivity.this.startActivity(i);
				}
			}, 2000);
		}
	}

	
	public void onResume() {
	    super.onResume();
	    MobclickAgent.onResume(this);
	}
	public void onPause() {
	    super.onPause();
	    MobclickAgent.onPause(this);
	}
}
